package com.study.mq;

import com.rabbitmq.client.*;
import lombok.SneakyThrows;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class MqConsumer {
	public static void main(String[] args) throws Exception {
		Connection connection = MqUtils.getConnection();

		Channel channel = connection.createChannel();
		channel.basicQos(1);
		channel.basicConsume("hello", false, new DefaultConsumer(channel){
			@SneakyThrows
			@Override
			public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
				TimeUnit.SECONDS.sleep(1);
				System.out.println(new String(body));
				channel.basicAck(envelope.getDeliveryTag(),false);
			}
		});
	}
}
